package com.geetour.columbus.region.controller;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;

import com.geetour.columbus.common.model.D.City;
import com.geetour.columbus.common.model.D.District;
import com.geetour.columbus.common.model.D.Province;
import com.geetour.columbus.common.service.IRegionDictService;

@Controller
public class RegionDictController {

    private IRegionDictService regionDictServiceImpl;

    @Autowired
    public void setRegionDictServiceImpl(IRegionDictService regionDictServiceImpl) {
        this.regionDictServiceImpl = regionDictServiceImpl;
    }

    @RequestMapping("/region/getAllProvince.json")
    public ModelAndView queryAllProvince() {
        ModelAndView mv = new ModelAndView();
        List<Province> provinces = regionDictServiceImpl.getAllProvinces();
        mv.addObject("flag", 1);
        mv.addObject("message", "success");
        mv.addObject("data", provinces);
        return mv;
    }

    @RequestMapping("/region/getCityByProvince.json")
    public ModelAndView queryCityByProvince(Long provinceId) {
        ModelAndView mv = new ModelAndView();
        if (provinceId == null) {
            return mv;
        }
        List<City> citys = regionDictServiceImpl.getCitysByProvinceId(provinceId);
        mv.addObject("flag", 1);
        mv.addObject("message", "success");
        mv.addObject("data", citys);
        return mv;
    }

    @RequestMapping("/region/getDistrictByCity.json")
    public ModelAndView queryDistrictByCity(Long cityId) {
        ModelAndView mv = new ModelAndView();
        if (cityId == null) {
            return mv;
        }
        List<District> districts = regionDictServiceImpl.getDistrictsByCityId(cityId);
        mv.addObject("flag", 1);
        mv.addObject("message", "success");
        mv.addObject("data", districts);
        return mv;
    }
}
